all repos — caroster @ 8a4f9e069b406ad3b9c2405dbef767b2a5304477

[Octree] Group carpool to your event https://caroster.io

frontend/pages/e/[uuid]/options.tsx (view raw)

 1import Box from '@mui/material/Box';
 2import Container from '@mui/material/Container';
 3import {PropsWithChildren} from 'react';
 4import pageUtils from '../../../lib/pageUtils';
 5import useEventStore from '../../../stores/useEventStore';
 6import EventLayout, {TabComponent} from '../../../layouts/Event';
 7import {EventByUuidDocument} from '../../../generated/graphql';
 8import CarosterPlusSettings from '../../../containers/CarosterPlusSettings';
 9import {getLocaleForLang} from '../../../lib/getLocale';
10import theme from '../../../theme';
11
12interface Props {
13  eventUUID: string;
14  announcement?: string;
15}
16
17const Page = (props: PropsWithChildren<Props>) => {
18  return <EventLayout {...props} Tab={OptionsTab} />;
19};
20
21const OptionsTab: TabComponent<Props> = () => {
22  const event = useEventStore(s => s.event);
23
24  if (!event) return null;
25
26  return (
27    <Box position="relative">
28      <Container
29        sx={{
30          p: 4,
31          mt: 6,
32          mb: 11,
33          mx: 0,
34          [theme.breakpoints.down('md')]: {
35            p: 2,
36            mt: 13,
37          },
38        }}
39      >
40        <CarosterPlusSettings event={event} />
41      </Container>
42    </Box>
43  );
44};
45
46export const getServerSideProps = pageUtils.getServerSideProps(
47  async (context, apolloClient) => {
48    const {uuid} = context.query;
49    const {host = ''} = context.req.headers;
50    let event = null;
51
52    // Fetch event
53    try {
54      const {data} = await apolloClient.query({
55        query: EventByUuidDocument,
56        variables: {uuid},
57      });
58      event = data?.eventByUUID?.data;
59    } catch (error) {
60      return {
61        notFound: true,
62      };
63    }
64
65    const carosterPlusActivated =
66      event?.attributes?.enabled_modules?.includes('caroster-plus');
67
68    if (!carosterPlusActivated)
69      return {
70        redirect: {
71          destination: `/e/${uuid}/prices`,
72          permanent: false,
73        },
74      };
75
76    const description = await getLocaleForLang(
77      event?.attributes?.lang,
78      'meta.description'
79    );
80
81    return {
82      props: {
83        eventUUID: uuid,
84        metas: {
85          title: event?.attributes?.name || '',
86          description,
87          url: `https://${host}${context.resolvedUrl}`,
88        },
89      },
90    };
91  }
92);
93export default Page;